package com.appsl.persistance;

import com.appsl.manager.Parameters;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class OpenHelper extends SQLiteOpenHelper 
{	
	
	public static final int DB_VERSION = 1;
	
	public OpenHelper(Context context, String name, CursorFactory factory, int version) 
	{
		super(context, name, factory, version);
	}
	
	// Called when no database exists in disk and the helper class needs
	// to create a new one.
	@Override
	public void onCreate(SQLiteDatabase db) 
	{
		DDL.createSchema(db);
		//Do somthing with Act
	}
	
	// Called when there is a database version mismatch meaning that
	// the version of the database on disk needs to be upgraded to
	// the current version.
	@SuppressLint("DefaultLocale")
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
	{
		// Log the version upgrade.
		String logMsj = String.format("Upgrading from version %d to %d, which will destroy all old data", oldVersion, newVersion);
		Log.w("TaskDBAdapter", logMsj);
	    // Upgrade the existing database to conform to the new
	    // version. Multiple previous versions can be handled by
	    // comparing oldVersion and newVersion values.
	    // The simplest case is to drop the old table and create a new one.
		DDL.dropSchema(db);
	    // Create a new one.
	    onCreate(db);
	  }

	public static SQLiteDatabase getInstance(Activity act) {
		return act.openOrCreateDatabase(Parameters.DATABASE_NAME, Context.MODE_PRIVATE, null); 
	}

}
